<?php
class User
{
  public $studentid;
  public $cn;
  public $mail;
  public $displayname;
  public $first;
  public $initial;
  public $last;
  public $major;
  public $grade;

  // -- Public Static Methods -------------------------------------------------
  public static function getByUsername($cn)
  {
    $result = Common::query('user.getByUsername', array(
      'cn' => $cn
    ));

    if ($result && $row = $result->fetch_assoc())
      return User::load($row);

    return false;
  }

  public static function load($row)
  {
    return new User($row['studentid'], $row['cn'], $row['mail'],
      $row['displayname'], $row['first'], $row['initial'],
      $row['last'], $row['major'], $row['grade']);
  }
  
	public static function getAll()
	{
	  $result = Common::query('user.getAll');
	
	  $users = array();
	
	  while($result && $row = $result->fetch_assoc())
	    $users[] = User::load($row);
	
	  return $users;
	}
	
  // -- Public Instance Methods -----------------------------------------------
  public function __construct($studentid = '', $cn = '', $mail = '',
    $displayname = '', $first = '', $initial = '', $last = '',
    $major = '', $grade = '')
  {
    $this->studentid 	= $studentid;
    $this->cn  		 	= $cn;
    $this->displayname  = $displayname;
    $this->mail     	= $mail;
    $this->first 		= $first;
    $this->initial 		= $initial;
    $this->last 		= $last;
    $this->major 		= $major;
    $this->grade		= $grade;
  }
}
?>